var DianChiTable;
/****列表信息*/
function showDianChiList() {
	$.ajax( {
		url : 'dianChi/listPage.do',
		type : 'get',
		dataType : 'html',
		success : function(html) {
			$('#mainForm').html(html);
			
			setup();promptinfo();
			DianChiTable = $('#entTable').table( {
				width : '100%',
				form : {
					url : 'comm/search.do',
					id : '#entSearchForm',
					type : 'post',
					pageNumberText : '#pageNum'
				},
				pageable : true,
				selectable : true,
				colums : [ {
					columnName : '电池品牌',
					name : 'pinPai',
					handle:"toAddDianChi"
				}, {
					columnName : '电池型号',
					name : 'xingHao'
				}, {
					columnName : '市场换够价',
					name : 'marketPrice'
				}, {
					columnName : '本网换购价',
					name : 'ourPrice'
				}, {
					columnName : '创建时间',
					name : 'crateDate'
				}, {
					columnName : '更新时间',
					name : 'updateDate'
				}]
			});
			//绑定查询按钮 
		$('#searchDianChiBtn').click(function() {
			DianChiTable.refresh();
		});
		$(".comboBox").kendoComboBox({filter:"contains", suggest:true });
	}
	});
}

//去增加
function toAddDianChi(id) {
	var param = '?t=' + ts();
	if (id) {
		param += '&id=' + id;
	}
	
	$.get('dianChi/toAddDianChi.do' + param, function(html) {
		$('#commonDialogDiv').html(html);
		initSsxSelect();
		$('#commonDialogDiv').dialog( {
			modal : true,
			title : '电池信息表',
			width : 900,
			height : 600,
			buttons : {
				'保存' : function() {
					saveAddDianChi();
				},
				'取消' : function() {
					$(this).dialog('close');
				}
			}
		});
		validator = $("#DianChiForm").validate( {
			rules : {
				"model.name" : {
					required : true,
					maxlength : 20
				},
				"model.detailInfo":{
					maxlength : 150
				}
			},
			messages : {
				"model.name" : {
					required : "必填"
				}
			}
		});
	});
}
//去保存
function saveAddDianChi() {
	if (validator.form()) {
		$('#DianChiForm').ajaxSubmit( {
			url : 'dianChi/saveDianChi.do',
			type : 'post',
			dataType : 'json',
			success : function(data) {
				if (data.success) {
					showDialog('保存成功');
					$('#commonDialogDiv').dialog('close');
					DianChiTable.refresh();
				} else {
					showDialog('保存失败' + data.message);
				}
			}
		});
	}
}

//批量删除 
function toDeleteDianChi() {
	var ids = '';
	$('.ids').each(function() {
		if (this.checked == true) {
			ids += 'ids=' + this.value + '&';
		}
	});
	if (ids.length == 0) {
		showDialog('请至少选择一条记录！');
		return;
	}
	$('#commonDialogDiv').html('<p>确定要删除记录信息？</p>');
	$('#commonDialogDiv').dialog( {
		modal : true,
		width : 250,
		height : 160,
		buttons : {
			'确定' : function() {
				$(this).dialog('close');
				$.ajax( {
					url : 'dianChi/delete.do?' + ids,
					type : 'get',
					dataType : 'json',
					success : function(data) {
						if (data.success) {
							DianChiTable.refresh();
						} else {
							showDialog('删除失败，原因：' + data.message);
						}
					}
				});
			},
			'取消' : function() {
				$(this).dialog('close');
			}
		}
	});
}

function promptinfo()
{
    var s1 = document.getElementById('s1');
    var s2 = document.getElementById('s2');
    var s3 = document.getElementById('s3');
}
